package belle.com.myapp.DataBase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Title :排行榜数据库
 * Description :
 * Author:  Belle Guan    date : 2018/6/20 11:52
 * Update :                date :
 * Version : 1.0.0
 * Copyright : copyright(c) 浙江亚厦股份有限公司 2017 ~ 2020 版权所有
 *
 * @author guanjiali1
 */
public class DataBaseHelper extends SQLiteOpenHelper {
    /**
     * integer：整形
     * real：浮点型
     * text：文本类型
     * blob：二进制类型
     * PRIMARY KEY将id列设置为主键
     * AutoIncrement关键字表示id列是自动增长的
     */


    public static final String CREATE_MUSIC = "CREATE TABLE music("
            + "id integer PRIMARY KEY Autoincrement,"
            + "musicId integer,"
            + "coverImgUrl text,"
            + "name text)";

    public static final String CREATE_SONGS = "CREATE TABLE Songs("
            + "id integer PRIMARY KEY Autoincrement,"
            + "musicId integer,"
            + "musicName text,"
            + "arName text,"
            + "type integer)";

    private Context mContext;

    public DataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_MUSIC);
        db.execSQL(CREATE_SONGS);
        Toast.makeText(mContext, "Create succeeded", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists music");
        db.execSQL("drop table if exists Songs");
        onCreate(db);
    }
}
